<!DOCTYPE html>
<html xmlns:th="http://www.springframework.org/schema/jdbc">
<head>
    <meta charset="utf-8">
    <title>用户--添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/components/layuiadmin/layui/src/css/layui.css">
    <script src="/components/layuiadmin/layui/src/layui.js"></script>
    <script src='/base/js/jquery-3.4.1.min.js'></script>
    <script src="/modules/js/app.js"></script>
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">


    <div class="layui-form-item">
        <label class="layui-form-label">类别id</label>
        <div class="layui-input-inline">
            <select id="typeid" name="typeid" lay-verify="" lay-filter="gender">
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-inline">
            <input type="text" id="title" name="title" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">段子内容</label>
        <div class="layui-input-block">
            <textarea id="content" name="content" placeholder="请输入内容" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
</div>

<script>

    var form;

    layui.use(['form'], function () {
        form = layui.form;
        //监听提交
        layui.form.on('submit(layuiadmin-app-form-submit)', function (data) {
            data.field.id = parent.data.id;
            //data.field.id = parent.data.id;
            let result = Ajax.put(path + "/admin/astory/xjAstory/upd", data.field);
            let index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            parent.layer.msg(result.msg);
            //重载表格
            parent.xijiaRenderTable();
        });
        //
        init();
    });


    function init() {
        <!-- 父页面的值,赋值到当前页 -->
        $('#title').val(parent.data.title);
        $('#content').val(parent.data.content);

        // 加载类别
        var res = Ajax.get(parent.findAstoryCategoryList);
        let html = "";
        for (let i = 0; i < res.data.length; i++) {
            html += "<option value='" + res.data[i].typeid + "'>" + res.data[i].type + "</option>"
        }
        $("#typeid").html(html);

        // 回显会当前对应的列表
        $("#typeid").find("option").each(function () {
            if ($(this).val() == parent.data.typeid) {
                $(this).attr("selected", "selected");
            }
        });

        // 防止layui-from不刷新
        form.render();
    }

</script>
</body>
</html>
